package test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import test.mapper.ETradeTabMapper;
import test.dto.ETradeTab;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : hs-etrade-management
 * @ Author: XuLeHuang
 * @ Date: 2022/10/14 14:35
 * @ Description:
 */
@Controller
@RequestMapping("/system")
public class UpLoadTestController {

    @Autowired
    private ETradeTabMapper eTradeTabMapper;

    @RequestMapping("/toUploadPage")
    public String toUploadPage() {
        return "a";
    }

    @PostMapping("/upload")
    public String uploadIcon(MultipartFile uploadImg) throws IOException {
        byte[] bytes = uploadImg.getBytes();
        ETradeTab eTradeTab = new ETradeTab();
        eTradeTab.setSysId(UUID.randomUUID().toString());
        eTradeTab.setSysName("iconTest");
        eTradeTab.setSysCnName("图片上传测试");
        eTradeTab.setSysUrl("https://www.baidu.com");
        eTradeTab.setIcnoLink("https://www.baidu.com");
        eTradeTab.setIcnoFile(bytes);
        int rows = eTradeTabMapper.insertSelective(eTradeTab);
        return rows > 0 ? new String("200"): new String("500");
    }
    @PostMapping("/addTabWithPhoto")
    @ResponseBody
    public String addTabWithPhoto(ETradeTab eTradeTab, MultipartFile uploadImg) throws IOException {
            byte[] bytes = uploadImg.getBytes();
            eTradeTab.setSysId("9");
            eTradeTab.setIcnoFile(bytes);
            return eTradeTabMapper.insertSelective(eTradeTab) > 0 ? new String("应用新增成功") : new String("应用新增失败");
    }



}
